package team.kas.anime.controller;

import com.sun.javafx.logging.PulseLogger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import team.kas.anime.pojo.Comment;
import team.kas.anime.pojo.Result;
import team.kas.anime.pojo.Results;
import team.kas.anime.service.CommentService;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

@Controller
@RequestMapping("/comment")
public class CommentController {
    @Autowired
    private CommentService commentService;

    @RequestMapping("/comment")
    public String comment(){
        return "comment/comment-list";
    }

    @RequestMapping("/check")
    public String test(String id,HttpServletRequest request){
        request.getSession().setAttribute("id",id);
        return "comment/comment-edit";
    }
    @RequestMapping("/reportlist")
    public String reportlist(){
        return "comment/comment-report";
    }

    @RequestMapping(value = "/list", method = RequestMethod.GET)
    @ResponseBody
    public Result listcomment(String value,Integer page,Integer limit){
        return commentService.listcomment(value,page,limit);
    }
    @ResponseBody
    @RequestMapping("/delete")
    public Result delete(String id){

        return commentService.deleteBykey(id);
    }

    @ResponseBody
    @RequestMapping("/bulkdelete")
    public Result bulkdelete(String[] ids){

        return commentService.bulkdelete(ids);
    }
    @ResponseBody
    @RequestMapping("/listedit")
    public Results list(HttpServletRequest request){
        return commentService.list(request);
    }


    @ResponseBody
    @RequestMapping(value = "/report", method = RequestMethod.GET)
    public Result report(String value,Integer page,Integer limit){
        String val="1";
        return commentService.listcomment(val,page,limit);
    }
    @ResponseBody
    @RequestMapping("/reportsearch")
    public Result reportsearch(String value,Integer page,Integer limit){
        return commentService.reportsearch(value,page,limit);
    }
    @ResponseBody
    @RequestMapping("/searchall")
    public Result searchall(String value,Integer page,Integer limit){
        return commentService.searchall(value,page,limit);
    }

    //找出所有评论
    @RequestMapping("/listComment")
    @ResponseBody
    public List<Comment> listComment(String vid){
        List<Comment> list = commentService.getCommentListByVideoId(vid);
        return list;
    }
    //添加父评论
    @RequestMapping("/addcomment")
    @ResponseBody
    public Result addcomment(String vid ,String uid ,String content){
        Result result = commentService.addcomment(vid,uid,content);
        return result;
    }

    //添加回复
    @RequestMapping("/addreply")
    @ResponseBody
    public Result addreply(String content,Integer pid, String uid , String vid){
        Result result = commentService.addreply(content,pid,uid,vid);
        return result;
    }

    @RequestMapping("/post")
    public String post(){return "comment";}

    @RequestMapping("/addreplypost")
    public String addreplypost(){return"addreply"; }
}
